/** Fenetre d'acquisition des données de création d'un cadran Plan */
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.border.Border;

public class FenetreAcquisition {
	// fenetre cree et fenetre mere
	private JDialog fenetreAcquisition;
	private PagePrincipale pageP;
	
	// zones d'acquisitions
	private JTextField lat;
	private JTextField f;
	private JTextField longu;
	private JTextField larg;
	private JTextField ang;
	private JTextField xVal;
	private JTextField yVal;
	private JTextField zVal;
	
	/** Ouverture de la fenetre d'acquisition des donnees pour un cadran plan 
	 * 
	 * @param fenetrePrincipale la JFrame de la page principale
	 * @param horizontal un booleen a true si le cadran plan est horizontal, false s'il est vertical 
	 */
	public FenetreAcquisition(PagePrincipale pageP){
		this.pageP = pageP;
		initialisation();
		placerComposant();
	}
	
	/** creation de la fenetre */
	private void initialisation(){
		fenetreAcquisition = new JDialog(pageP.getFenetrePrincipale());
		fenetreAcquisition.setBounds(450,100,400,600);
		fenetreAcquisition.setTitle("Creer un cadran plan");
		fenetreAcquisition.setVisible(true);
	}

	/** placement et organisation des composants */
	private void placerComposant(){
		Border bordure = BorderFactory.createLineBorder(Color.black);
		
		// organisation verticale
		JPanel page = new JPanel();
	    page.setLayout(new BoxLayout(page, BoxLayout.PAGE_AXIS));
		
		///////////////////////////////
		//	Coordonnées géographiques
		///////////////////////////////
		JPanel coordPanneau = new JPanel();
		JLabel titre = new JLabel("Coordonnees geographiques",JLabel.CENTER);
		coordPanneau.setLayout(new BoxLayout(coordPanneau, BoxLayout.LINE_AXIS));
	    coordPanneau.setPreferredSize(new Dimension(400,150));
	    coordPanneau.add(titre);
	    
	    // latitude
	    JPanel latitudePanneau = new JPanel();
	    latitudePanneau.setPreferredSize(new Dimension(400,100));
	    latitudePanneau.setLayout(new BoxLayout(latitudePanneau, BoxLayout.LINE_AXIS));
	    JLabel latitude = new JLabel("Latitude :");
	    latitude.setPreferredSize(new Dimension(75,50));
	    latitudePanneau.add(Box.createRigidArea(new Dimension(75,0)));
	    latitudePanneau.add(latitude);
	    
	    lat = new JTextField();
	    lat.setHorizontalAlignment(JTextField.CENTER);
	    lat.setBackground(Color.orange);
	    lat.setPreferredSize(new Dimension(65,50));
	    lat.setBorder(bordure);
	    latitudePanneau.add(Box.createRigidArea(new Dimension(50,0)));
	    latitudePanneau.add(lat);
	    
	    JLabel deg = new JLabel("degres");
	    deg.setPreferredSize(new Dimension(50,50));
	    latitudePanneau.add(Box.createRigidArea(new Dimension(10,0)));
	    latitudePanneau.add(deg);
	    latitudePanneau.add(Box.createRigidArea(new Dimension(75,0)));
	    
	    // ajouts dans l'organisation verticale
	    page.add(Box.createRigidArea(new Dimension(0,10)));
	    page.add(coordPanneau);
	    page.add(Box.createRigidArea(new Dimension(0,10)));
	    page.add(latitudePanneau);
	    page.add(Box.createRigidArea(new Dimension(0,10)));
	    
	    // fuseau horaire
		if ( !pageP.isHeureSolaire() ) {		
		    JPanel fuseauPanneau = new JPanel();
		    fuseauPanneau.setPreferredSize(new Dimension(400,100));
		    fuseauPanneau.setLayout(new BoxLayout(fuseauPanneau, BoxLayout.LINE_AXIS));
		    JLabel fuseau = new JLabel("Fuseau horaire :");
		    fuseau.setPreferredSize(new Dimension(115,50));
		    fuseauPanneau.add(Box.createRigidArea(new Dimension(75,0)));
		    fuseauPanneau.add(fuseau);
		    
		    f = new JTextField();
		    f.setHorizontalAlignment(JTextField.CENTER);
		    f.setBackground(Color.orange);
		    f.setPreferredSize(new Dimension(100,50));
		    f.setBorder(bordure);
		    fuseauPanneau.add(Box.createRigidArea(new Dimension(10,0)));
		    fuseauPanneau.add(f);
		    fuseauPanneau.add(Box.createRigidArea(new Dimension(100,0)));
		    
		    // ajout dans l'organisation verticale
		    page.add(fuseauPanneau);
		    page.add(Box.createRigidArea(new Dimension(0,10)));
		}	    
	    
	    /////////////////////////
	    //dimensions du plateau
	    /////////////////////////
	    JPanel dimPanneau = new JPanel();
		JLabel dimensions = new JLabel("Definition du plateau",JLabel.CENTER);
		dimPanneau.setLayout(new BoxLayout(dimPanneau, BoxLayout.LINE_AXIS));
	    dimPanneau.setPreferredSize(new Dimension(400,150));
	    dimPanneau.add(dimensions);
		
		
		// longueur
		JPanel longPanneau = new JPanel();
		longPanneau.setPreferredSize(new Dimension(400,100));
		longPanneau.setLayout(new BoxLayout(longPanneau, BoxLayout.LINE_AXIS));
	    JLabel longueur = new JLabel("Longueur :");
	    longueur.setPreferredSize(new Dimension(75,50));
	    longPanneau.add(Box.createRigidArea(new Dimension(75,0)));
	    longPanneau.add(longueur);
	    
	    longu = new JTextField();
	    longu.setHorizontalAlignment(JTextField.CENTER);
	    longu.setBackground(Color.orange);
	    longu.setPreferredSize(new Dimension(90,50));
	    longu.setBorder(bordure);
	    longPanneau.add(Box.createRigidArea(new Dimension(50,0)));
	    longPanneau.add(longu);
	    
	    JLabel metre = new JLabel("m");
	    metre.setPreferredSize(new Dimension(25,50));
	    longPanneau.add(Box.createRigidArea(new Dimension(10,0)));
	    longPanneau.add(metre);
	    longPanneau.add(Box.createRigidArea(new Dimension(75,0)));
	    
	    // largeur
	    JPanel largPanneau = new JPanel();
		largPanneau.setPreferredSize(new Dimension(400,100));
		largPanneau.setLayout(new BoxLayout(largPanneau, BoxLayout.LINE_AXIS));
	    JLabel largeur = new JLabel("Largeur :");
	    largeur.setPreferredSize(new Dimension(75,50));
	    largPanneau.add(Box.createRigidArea(new Dimension(75,0)));
	    largPanneau.add(largeur);
	    
	    larg = new JTextField();
	    larg.setHorizontalAlignment(JTextField.CENTER);
	    larg.setBackground(Color.orange);
	    larg.setPreferredSize(new Dimension(90,50));
	    larg.setBorder(bordure);
	    largPanneau.add(Box.createRigidArea(new Dimension(50,0)));
	    largPanneau.add(larg);
	    
	    JLabel metr2 = new JLabel("m");
	    metr2.setPreferredSize(new Dimension(25,50));
	    largPanneau.add(Box.createRigidArea(new Dimension(10,0)));
	    largPanneau.add(metr2);
	    largPanneau.add(Box.createRigidArea(new Dimension(75,0)));
	    
	    // angle
	    JPanel anglePanneau = new JPanel();
		anglePanneau.setPreferredSize(new Dimension(400,100));
		anglePanneau.setLayout(new BoxLayout(anglePanneau, BoxLayout.LINE_AXIS));
	    JLabel angle = new JLabel("Angle :");
	    angle.setPreferredSize(new Dimension(75,50));
	   	anglePanneau.add(Box.createRigidArea(new Dimension(75,0)));
	   	anglePanneau.add(angle);
	    
	    ang = new JTextField();
	    ang.setHorizontalAlignment(JTextField.CENTER);
	    ang.setBackground(Color.orange);
	    ang.setPreferredSize(new Dimension(65,50));
	    ang.setBorder(bordure);
	    anglePanneau.add(Box.createRigidArea(new Dimension(50,0)));
	    anglePanneau.add(ang);
	    
	    JLabel deg2 = new JLabel("degres");
	    deg2.setPreferredSize(new Dimension(50,50));
	    anglePanneau.add(Box.createRigidArea(new Dimension(10,0)));
	    anglePanneau.add(deg2);
	    anglePanneau.add(Box.createRigidArea(new Dimension(75,0)));
	    
	    // ajouts dans l'organisation verticale
	    page.add(dimPanneau);
	    page.add(Box.createRigidArea(new Dimension(0,10)));
	    page.add(longPanneau);
	    page.add(Box.createRigidArea(new Dimension(0,10)));
	    page.add(largPanneau);
	    page.add(Box.createRigidArea(new Dimension(0,10)));
	    page.add(anglePanneau);
	    page.add(Box.createRigidArea(new Dimension(0,10)));
	    
	    
	    
	    ///////////////////////
	    //Coordonnees du style
	    ///////////////////////	
  		JPanel stylePanneau = new JPanel();
  		JLabel styleT = new JLabel("Coordonnees du style",JLabel.CENTER);
		stylePanneau.setLayout(new BoxLayout(stylePanneau, BoxLayout.LINE_AXIS));
	    stylePanneau.setPreferredSize(new Dimension(400,150));
	    stylePanneau.add(styleT);
  		
  		// coordonnee en X
  	    JPanel xPanneau = new JPanel();
  	    xPanneau.setPreferredSize(new Dimension(400,100));
  	    xPanneau.setLayout(new BoxLayout(xPanneau, BoxLayout.LINE_AXIS));
  	    JLabel x = new JLabel("X :");
  	    x.setPreferredSize(new Dimension(50,50));
  	  	xPanneau.add(Box.createRigidArea(new Dimension(100,0)));
  	    xPanneau.add(x);
  	    xPanneau.add(Box.createRigidArea(new Dimension(50,0)));
  	    
  	    xVal = new JTextField();
  	    xVal.setHorizontalAlignment(JTextField.CENTER);
  	    xVal.setBackground(Color.orange);
  	    xVal.setPreferredSize(new Dimension(90,50));
  	    xVal.setBorder(bordure);
  	    xPanneau.add(xVal);
  	    
  	    JLabel metre3 = new JLabel("m");
  	    metre3.setPreferredSize(new Dimension(25,50));
  	    xPanneau.add(Box.createRigidArea(new Dimension(10,0)));
  	    xPanneau.add(metre3);
  	    xPanneau.add(Box.createRigidArea(new Dimension(75,0)));
  	    
  	    // coordonnee en Y
  	    JPanel yPanneau = new JPanel();
	    yPanneau.setPreferredSize(new Dimension(400,100));
	    yPanneau.setLayout(new BoxLayout(yPanneau, BoxLayout.LINE_AXIS));
	    JLabel y = new JLabel("Y :");
	    y.setPreferredSize(new Dimension(50,50));
	    yPanneau.add(Box.createRigidArea(new Dimension(100,0)));
	    yPanneau.add(y);
	    yPanneau.add(Box.createRigidArea(new Dimension(50,0)));
	    
	    yVal = new JTextField();
	    yVal.setHorizontalAlignment(JTextField.CENTER);
	    yVal.setBackground(Color.orange);
	    yVal.setPreferredSize(new Dimension(90,50));
	    yVal.setBorder(bordure);
	    yPanneau.add(yVal);
	    
	    JLabel metre4 = new JLabel("m");
	    metre4.setPreferredSize(new Dimension(25,50));
	    yPanneau.add(Box.createRigidArea(new Dimension(10,0)));
	    yPanneau.add(metre4);
	    yPanneau.add(Box.createRigidArea(new Dimension(75,0)));
	    
	    // coordonnee en Z
	    JPanel zPanneau = new JPanel();
  	    zPanneau.setPreferredSize(new Dimension(400,100));
  	    zPanneau.setLayout(new BoxLayout(zPanneau, BoxLayout.LINE_AXIS));
  	    JLabel z = new JLabel("Z :");
  	    z.setPreferredSize(new Dimension(50,50));
  	    zPanneau.add(Box.createRigidArea(new Dimension(100,0)));
  	    zPanneau.add(z);
  	    zPanneau.add(Box.createRigidArea(new Dimension(50,0)));
  	    
  	    zVal = new JTextField();
  	    zVal.setHorizontalAlignment(JTextField.CENTER);
  	    zVal.setBackground(Color.orange);
  	    zVal.setPreferredSize(new Dimension(90,50));
  	    zVal.setBorder(bordure);
  	    zPanneau.add(zVal);
  	    
  	    JLabel metre5 = new JLabel("m");
  	    metre5.setPreferredSize(new Dimension(25,50));
  	    zPanneau.add(Box.createRigidArea(new Dimension(10,0)));
  	    zPanneau.add(metre5);
  	    zPanneau.add(Box.createRigidArea(new Dimension(75,0)));
  	  
  	    // ajouts dans l'organisation verticale
  	    page.add(stylePanneau);
	    page.add(Box.createRigidArea(new Dimension(0,10)));
	    page.add(xPanneau);
	    page.add(Box.createRigidArea(new Dimension(0,10)));
	    page.add(yPanneau);
	    page.add(Box.createRigidArea(new Dimension(0,10)));
	    page.add(zPanneau);
	    page.add(Box.createRigidArea(new Dimension(0,10)));
	    
	    ///////////
	    // Boutons
	    ///////////
	    JPanel boutonPanneau = new JPanel();
  	    boutonPanneau.setPreferredSize(new Dimension(400,100));
  	    boutonPanneau.setLayout(new BoxLayout(boutonPanneau, BoxLayout.LINE_AXIS));
	    
  	    JButton annuler = new JButton("Annuler");
  	    boutonPanneau.add(annuler);
  	    annuler.addActionListener(new ActionListener(){
  	    	public void actionPerformed(ActionEvent e){
  	    		fenetreAcquisition.dispose();
  	    	}
  	    });
  	    
  	  	boutonPanneau.add(Box.createRigidArea(new Dimension(100,0)));
  	    JButton valider = new JButton("Valider");
  	    boutonPanneau.add(valider);
  	    valider.addActionListener(new EcouteurValiderPlan(pageP, this));
  	    
  	    // ajouts dans l'organisation verticale
  	    page.add(Box.createRigidArea(new Dimension(0,30)));
  	    page.add(boutonPanneau);
  	    page.add(Box.createRigidArea(new Dimension(0,10)));
  	    
  	    // ajouter le tout sur la JDialog
	    fenetreAcquisition.getContentPane().add(page);
	}

	///////////////////////////
	// Get et Set des fenetres
	///////////////////////////
	
	public JDialog getFenetreAcquisition() {
		return fenetreAcquisition;
	}

	public void setFenetreAcquisition(JDialog fenetreAcquisition) {
		this.fenetreAcquisition = fenetreAcquisition;
	}
	
	public PagePrincipale getPageP() {
		return pageP;
	}

	public void setPageP(PagePrincipale pageP) {
		this.pageP = pageP;
	}

	//////////////////////////////////////
	// Get et Set des zones d'acquisition
	//////////////////////////////////////
	
	public JTextField getLat() {
		return lat;
	}

	public void setLat(JTextField l) {
		this.lat = l;
	}

	public JTextField getF() {
		return f;
	}

	public void setF(JTextField f) {
		this.f = f;
	}

	public JTextField getLongu() {
		return longu;
	}

	public void setLongu(JTextField longu) {
		this.longu = longu;
	}

	public JTextField getLarg() {
		return larg;
	}

	public void setLarg(JTextField larg) {
		this.larg = larg;
	}
	
	public JTextField getAng() {
		return ang;
	}

	public void setAngle(JTextField ang) {
		this.ang = ang;
	}

	public JTextField getxVal() {
		return xVal;
	}

	public void setxVal(JTextField xVal) {
		this.xVal = xVal;
	}

	public JTextField getyVal() {
		return yVal;
	}

	public void setyVal(JTextField yVal) {
		this.yVal = yVal;
	}

	public JTextField getzVal() {
		return zVal;
	}

	public void setzVal(JTextField zVal) {
		this.zVal = zVal;
	}
}